package com.future.demo;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;

import static java.lang.Runtime.getRuntime;

/**
 * Created by FutureAdmin on 14-3-12.
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        String command = "cmd";
        String cmdline = "dir";
        Process proc = getRuntime().exec(command);
        OutputStream outputStream = proc.getOutputStream();
        InputStreamReader inputStreamReader = new InputStreamReader(proc.getInputStream(), "GBK");
        outputStream.write(cmdline.getBytes());
        outputStream.flush();
        outputStream.close();

        char[] buf = new char[2048];
        int size = 0;
        StringBuilder sb = new StringBuilder();
        //读取屏幕输出
        while ((size = inputStreamReader.read(buf)) != -1) {
            sb.append(buf, 0, size);
        }
        System.out.println(sb.toString());
        //关闭输入流
        inputStreamReader.close();

    }
}
